package com.ioidea.room.bean

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.Update
import kotlinx.coroutines.flow.Flow

@Entity
data class GroupName(
    @PrimaryKey
    var groupIdJkSn: String,

    var groupId: Int,
    var groupName: String,
    var jkSn: String
)

@Dao
interface GroupDeviceDao{


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertGroupDevice(groupName: GroupName)

    @Update
    fun replaceGroupDevice(groupName: GroupName)

    @Query("DELETE FROM GroupName WHERE jkSn==:jkSn")
    fun clearGroupDeviceByJKSn(jkSn: String)


    @Query("SELECT * FROM GroupName")
    fun getAllGroupDevicesFlow(): Flow<MutableList<GroupName>>

    @Query("SELECT * FROM GroupName")
    fun getAllGroupDevicesList(): List<GroupName>

    @Query(
        "SELECT * FROM GroupName WHERE jkSn==:jkSn "
    )
    fun getGroupDevicesByJkSnList(jkSn: String):MutableList<GroupName>

    @Query(
        "SELECT * FROM GroupName WHERE jkSn==:jkSn ORDER BY groupId ASC "
    )
    fun getGroupDevicesByJkSnFlow(jkSn: String): Flow<MutableList<GroupName>>


    @Delete
    fun deleteGroupDevice(device: GroupName)


}
